package com.xiaoyu.client.adapter.mall;

import android.content.Context;
import android.media.JetPlayer;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.xiaoyu.client.R;
import com.xiaoyu.client.model.goods.GoodsParam;

import java.util.ArrayList;
import java.util.List;

/**
 * 商品类型页面的商品列表适配器
 */
public class GoodsForTagAdapter extends BaseAdapter {
    private Context mContext;
    private List<GoodsParam> mList = new ArrayList<>();

    public GoodsForTagAdapter(Context mContext, List<GoodsParam> mList) {
        this.mContext = mContext;
        this.mList = mList;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public GoodsParam getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    class ViewHolder{
        ImageView img;//商品图片
        TextView name;
        TextView price;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_goods_for_more_tag,parent,false);
            holder = new ViewHolder();
            holder.img = convertView.findViewById(R.id.item_goods_img);
            holder.name = convertView.findViewById(R.id.item_goods_name);
            holder.price = convertView.findViewById(R.id.item_goods_price);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }

        Glide.with(mContext).load(getItem(position).getGoodsimg()).into(holder.img);
        holder.name.setText(getItem(position).getGoodsname());
        holder.price.setText(getItem(position).getGoodsprice1());
        return convertView;
    }

    public void updateList(List<GoodsParam> list){
        this.mList = list;
        this.notifyDataSetChanged();
    }
}
